//! PartyMod - OFBiz Party Entity Management Module
//!
//! This module provides comprehensive management for OFBiz party-related entities,
//! including party relations, user management, organization member management,
//! customer relationship management, and human resource management.

pub mod client;
pub mod data;
pub mod models;
pub mod services;

#[cfg(test)]
pub mod tests;

// Re-export commonly used types
pub use client::EntityClient;
pub use models::*;
pub use services::*;

// Generated gRPC code
pub mod entity_service {
    tonic::include_proto!("entity_service");
}

/// Result type alias for this crate
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

/// Error types for PartyMod
#[derive(thiserror::Error, Debug)]
pub enum PartyModError {
    #[error("gRPC client error: {0}")]
    GrpcError(#[from] tonic::Status),
    
    #[error("Connection error: {0}")]
    ConnectionError(String),
    
    #[error("Entity not found: {0}")]
    EntityNotFound(String),
    
    #[error("Invalid data: {0}")]
    InvalidData(String),
    
    #[error("Serialization error: {0}")]
    SerializationError(#[from] serde_json::Error),
    
    #[error("Other error: {0}")]
    Other(String),
}

/// Configuration for PartyMod
#[derive(Debug, Clone, serde::Deserialize)]
pub struct PartyModConfig {
    pub entsrv_host: String,
    pub entsrv_port: u16,
    pub timeout_seconds: u64,
}

impl Default for PartyModConfig {
    fn default() -> Self {
        Self {
            entsrv_host: "localhost".to_string(),
            entsrv_port: 50051,
            timeout_seconds: 30,
        }
    }
}